<?php

namespace App\Events\Cruise;

use App\Models\Cruise\CruiseOrderModel;
use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log;

class CruiseOrderChangeEvent
{
    use Dispatchable, InteractsWithSockets, SerializesModels;

    public int $cruiseOrderId;
    public int $templateType;
    public array $oldCruiseOrderModel;
    public array $newCruiseOrderModel;

    /**
     * Create a new event instance.
     *
     * @return void
     */
    public function __construct(
        int $cruiseOrderId,
        int $templateType,
        ?CruiseOrderModel $oldCruiseOrderModel,
        ?CruiseOrderModel $newCruiseOrderModel
    ) {
        $this->cruiseOrderId       = $cruiseOrderId;
        $this->templateType        = $templateType;
        $this->oldCruiseOrderModel = $oldCruiseOrderModel ? $oldCruiseOrderModel->toArray() : [];
        $this->newCruiseOrderModel = $newCruiseOrderModel ? $newCruiseOrderModel->toArray() : [];
    }

    /**
     * Get the channels the event should broadcast on.
     *
     * @return Channel
     */
    public function broadcastOn()
    {
        return new PrivateChannel('channel-name');
    }
}
